//
// Created by dxyinme on 2021/11/6.
//

#ifndef FPSTYLE_CONDITION_H
#define FPSTYLE_CONDITION_H

#include <future>
#include <unordered_map>
#include <functional>

namespace FPStyle {

template <class F, class... Args>
void If(bool case1, F&& f, Args&&... args);

template <class F, class... Args>
auto IfCalculate(bool case1, F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>;

template <class F, class FElse>
void IfElse(bool case1, F&& f, FElse&& f_else);


bool And(bool case1, bool case2);

bool Or(bool case1, bool case2);



// impl
template <class F, class... Args>
void If(bool case1, F&& f, Args&&... args) {
  if (case1) {
    f(args...);
  }
}

template <class F, class... Args>
auto IfCalculate(bool case1, F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type> {
  if (case1) {
    return f(args...);
  }
}

template <class F, class FElse>
void IfElse(bool case1, F&& f, FElse&& f_else) {
  if (case1) {
    f();
  } else {
    f_else();
  }
}



}

#endif //FPSTYLE_CONDITION_H
